package com.usian.admin.listener;

import com.usian.admin.service.WemediaNewsAutoScanService;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Log4j2
public class WmNewsListener {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = "wmnews_submit")
    public void getMsg(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            Integer wmnewsId = Integer.valueOf(record.value().toString());

            boolean result = wemediaNewsAutoScanService.autoScanByMediaNewsId(wmnewsId);
            if(result){
                log.info("审核成功，result="+result);
            }else{
                log.info("审核失败，result="+result);
            }
        }

    }
}
